﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TestCommonWindow.View;
using TestCommonWindow.Common;
using System.IO;

namespace TestCommonWindow
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            #region 首次生成数据
            //BusinessProcess.SerializeToXml(Path.Combine(Environment.CurrentDirectory, "AppConfig.cfg"), new ConfigInfo
            //{
            //    SqlParameterInfo = new SqlParameter
            //    {
            //        Server = "192.168.135.252",
            //        Database = "Test",
            //        UserId = "sa",
            //        Password = "kerrlog@123"
            //    },
            //    EmulatorInfos = new List<Emulator> {
            //       new Emulator{
            //          Name="RFMDComm2",
            //          PartInfos=new List<Part>{
            //                  new Part{
            //                      PartNumber="QM13031V1.37",
            //                      RegisterInfos=new List<Register>
            //                  {

            //            new Register
            //            {
            //                IsTestItem=false,
            //                Description="MAIN_USID",
            //                RegisterName="Reg31",
            //                Address="0x001F",
            //                StartBitField=7,
            //                StopBitField=0

            //            },
            //             new Register
            //            {
            //                IsTestItem=true,
            //                Description="USID",
            //                UpperLimit=6,
            //                LowerLimit=6,
            //                RegisterName="Reg31",
            //                Address="0x001F",
            //                StartBitField=7,
            //                StopBitField=4

            //            },
            //              new Register
            //            {
            //                RegisterName="Reg31",
            //                IsTestItem=false,
            //                Description="MFG_ID_MSB",
            //                Address="0x001F",
            //                StartBitField=3,
            //                StopBitField=0

            //            },
            //               new Register
            //            {
            //                RegisterName="Reg29",
            //                Description="PRODUCT_ID",
            //                IsTestItem=false,
            //                Address="0x001D",
            //                StartBitField=7,
            //                StopBitField=0

            //            },
            //                   new Register
            //            {
            //                RegisterName="Reg30",
            //                Description="MANUFACTURER_ID",
            //                IsTestItem=false,
            //                Address="0x001E",
            //                StartBitField=7,
            //                StopBitField=0

            //            },
            //                          new Register
            //            {
            //                RegisterName="Reg32",
            //                Description="EXT_PRODUCT_ID",
            //                IsTestItem=false,
            //                Address="0x0020",
            //                StartBitField=7,
            //                StopBitField=0

            //            },
            //              new Register
            //            {
            //                RegisterName="Reg33",
            //                Description="REVISION_ID",
            //                IsTestItem=false,
            //                Address="0x0021",
            //                StartBitField=7,
            //                StopBitField=0

            //            }
            //           }}
            //       } }
            //  }

            //});
            #endregion
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            App app = new App();
            app.Run(new MainWindow());
           
        }
        private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {

            List<string> engineDlls = new List<string>();
            engineDlls.AddRange(new string[] { "LoaderEngine", "RFMDMPSSE", "Bin", "Utilities" });
            var assemblyName = new AssemblyName(args.Name);
            if (engineDlls.Contains(assemblyName.Name))
            {
                string dllLocation = System.IO.Path.Combine(Environment.CurrentDirectory, "DarwinDll\\" + assemblyName.Name + ".dll");
                if (System.IO.File.Exists(dllLocation))
                {
                    return Assembly.LoadFrom(dllLocation);
                }
            }
            return null;
        }
    }
}
